#include <list>

#include <gmpxx.h>
#include <gmp.h>

int main(int argc, char **argv) {
  std::list<mpz_class> candidates;

  unsigned long a2, a3, a5, a7, a11, a13;

  for (a2 = 0; a2 < 11; a2++) {
    unsigned long b2 = 2^a2;
    for (a3 = 0; a3 < 6; a3++) {
      unsigned long b3 = 3^a3;
      for (a5 = 0; a5 < 3; a5++) {
        unsigned long b5 = 5^a5;
        for (a7 = 0; a7 < 2; a7++) {
          unsigned long b7 = 7^a7;
          for (a11 = 0; a11 < 2; a11++) {
            unsigned long b11 = 11^a11;
            for (a13 = 0; a13 < 2; a13++) {
              unsigned long b13 = 13^a13;

              mpz_class prod(1);

              prod = prod * a2;
              prod = prod * a3;
              prod = prod * a5;
              prod = prod * a7;
              prod = prod * a11;
              prod = prod * a13;

              candidates.push_back(prod);
            }
          }
        }
      }
    }
  }

  std::list<mpz_class> selected;

  std::list<mpz_class>::iterator it;
  for (it = candidates.begin(); it != candidates.end(); it++) {
    mpz_t candidate;

    mpz_init(candidate);
    mpz_set(candidate,it->get_mpz_t());

    mpz_add_ui(candidate, candidate, 1UL);
    if (mpz_probab_prime_p(candidate, 5) != 0) {
      mpz_class s(candidate);

      selected.push_back(s);
    }
  }

  selected.sort();
  selected.unique();

  for (it = selected.begin(); it != selected.end(); it++) {
    gmp_printf("%Zd\n", it->get_mpz_t());
  }

  return 0;
}
